package cn.ljh.zard.listen.register;

import cn.ljh.zard.listen.BaseListener;
import cn.ljh.zard.listen.scan.AutoScanListener;
import cn.ljh.zard.listen.scan.IAutoScanListener;

import java.util.ArrayList;
import java.util.Collection;

public class ListenerRegister implements IListenerRegister {


    private Collection<BaseListener> listeners = new ArrayList<>(16);

    @Override
    public void registerListener(BaseListener baseListener) {
        if (listeners.contains(baseListener)) {

        } else {
            listeners.add(baseListener);
        }
    }

    @Override
    public Collection<BaseListener> getAllListener() {

        IAutoScanListener autoScanListener = new AutoScanListener();

        if (listeners.isEmpty()) {
            listeners = autoScanListener.scan();
        }

        return listeners;

    }

}
